home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / nftp102.zip / STAT.CMD < prev    next >
OS/2 REXX Batch file  |  1997-04-16  |  4KB  |  131 lines

  1. /*
  2.  REXX program to extract statistics from NFTP.FLS file     Version 0.2
  3.  Freely distributable, but copyright by Tóth Ferenc <etus@alarmix.net>
  4.  Please mail any suggestinos and/or bug report to the author.
  5.  
  6.  To do:
  7.  - option to count uploads/downloads separately
  8.  - option to sort sites according to speed or down/upload size
  9.  - option to list only specified time interval or sites
  10.  */
  11.  
  12. inputfile = "list.txt"
  13. outputfile = "nftp.sta"
  14.  
  15. "@del" outputfile ">nul 2>&1"
  16.  
  17. parse arg inputfiles
  18.  
  19. if inputfiles="" then
  20. do
  21.     say
  22.     say "NFTP statistics requires a parameter: the name of the log file."
  23.     say "This can contain wildcard characters, so you can process more files easily."
  24.     exit
  25. end
  26.  
  27. "@copy "inputfiles" list.txt > nul"
  28.  
  29. noecho = LINEOUT(outputfile, "Date      Megabyte     average speed (cps)")
  30. noecho = LINEOUT(outputfile, "------------------------------------------")
  31.  
  32. /* Calculate the number of files and store their date/time, size etc. */
  33. files=1
  34. DO WHILE LINES(inputfile) > 0
  35.     line = LINEIN(inputfile)
  36.     month.files = SUBSTR(line, 4, 2)
  37.     year.files = SUBSTR(line, 7, 2)
  38.     time.files = SUBSTR(line, 10, 5)
  39.     size.files = SUBSTR(line, 16, 9)
  40.     if pos("(", line) = 0 then
  41.     do
  42.     /* old style log without speed */
  43.         speed.files = 1
  44.         site.files = SUBSTR(line, 27, POS(":", line, 27)-27)
  45.     end
  46.     else
  47.     do
  48.     /* new style with speed */
  49.         speed.files = SUBSTR(line, 26, 7)
  50.         site.files = SUBSTR(line, 40, POS(":", line, 40)-40)
  51.     end
  52.     if speed.files = 0 then speed.files = 1
  53.     site = site.files
  54.     bytespersite.site=0
  55.     timepersite.site=0
  56.     files=files+1
  57.     END
  58. files=files-1
  59. month=month.1
  60. year=year.1
  61. bytes=0
  62. time=0
  63. total=0
  64. totaltime=0
  65.  
  66. /* summary */
  67. do counter=1 to files
  68.     site = site.counter
  69.     bytespersite.site=bytespersite.site + size.counter
  70.     timepersite.site=timepersite.site+size.counter/speed.counter
  71.     
  72.     if (month.counter = month) & (year.counter = year) then do
  73.         bytes=bytes+size.counter
  74.         time=time+size.counter/speed.counter
  75.     end
  76.     else
  77.     do
  78.         if time=0 then time=1
  79.         speed=FORMAT(bytes/time,16,0)
  80.         if speed > 999 then speed=RIGHT(REVERSE(INSERT(",", REVERSE(STRIP(speed)), 3)),16)
  81.         byte=FORMAT(bytes/1024/1024,8,2)
  82.         donotecho = LINEOUT(outputfile, month"/"year||byte||speed)
  83.         
  84.         total=total+byte
  85.         totaltime=totaltime+time
  86.         month=month.counter
  87.         year=year.counter
  88.         bytes=size.counter
  89.         time=size.counter/speed.counter
  90.     end
  91.     END
  92.  
  93. if time=0 then time=1
  94. speed=FORMAT(bytes/time,16,0)
  95. if speed > 999 then speed=RIGHT(REVERSE(INSERT(",", REVERSE(STRIP(speed)), 3)),16)
  96. byte=FORMAT(bytes/1024/1024,8,2)
  97. donotecho = LINEOUT(outputfile, month"/"year||byte||speed)
  98.  
  99. noecho = LINEOUT(outputfile, "")
  100. noecho = LINEOUT(outputfile, "Site                                      Megabyte     average speed (cps)")
  101. noecho = LINEOUT(outputfile, "--------------------------------------------------------------------------")
  102. noecho = LINEOUT(outputfile, "")
  103.  
  104. do numsites=1 to files
  105.     site=site.numsites
  106.     if numsites > 1 then
  107.     do
  108.         check = numsites -1 
  109.         do while (site.check <> site) & (check > 0)
  110.             check = check - 1
  111.         end
  112.     end
  113.     
  114.     if (site.check<>site) then do
  115.         if timepersite.site=0 then timepersite.site=1
  116.         speed=FORMAT(bytespersite.site/timepersite.site,16,0)
  117.         if speed > 999 then speed=RIGHT(REVERSE(INSERT(",", REVERSE(STRIP(speed)), 3)),16)
  118.         byte=FORMAT(bytespersite.site/1024/1024,8,2)
  119.         if speed=1 then speed=""
  120.         donotecho = LINEOUT(outputfile, overlay(" ", site,38,0)||byte||"    "||speed)
  121.     end
  122. end
  123.  
  124. totalspeed=FORMAT(total*1024*1024/totaltime,16,0)
  125. if totalspeed > 999 then totalspeed=RIGHT(REVERSE(INSERT(",", REVERSE(STRIP(totalspeed)), 3)),16)
  126. noecho = LINEOUT(outputfile, "--------------------------------------------------------------------------")
  127. noecho = LINEOUT(outputfile, "Total           " right(total, 31) right(totalspeed, 19))
  128. noecho = LINEOUT(list.txt)
  129. "@del list.txt"
  130. EXIT
  131.